package gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import client.Main;
import client.ReportControl;

public class Report_GUI extends JFrame implements ActionListener, TableModelListener{
	
	public String[] months={" ","01","02","03","04","05","06","07","08","09","10","11","12"};
	public String[] compOptions={"Handled", "Non-Handled"};
	public Object[][] data = null;
	public String[] columnNames = {"Complaint ID", "Complaint Description", "Response", "Compensation"};
	public String[] columnNames1 = {"Survry ID", "Question 1", "Question 2", "Question 3", "Question 4", "Question 5", "Question 6"};
	public String[] columnInventory = {"Name","Color","Quantity"};
	public String[] quarters = {"First","Second","Third","Forth"};
	public String[] columnIncome = {"Item ID","Item Name","Color","Quantity","Income"};
	public String[] columnOrder = {"Order ID","Item ID","Item Name","Color","Quantity","Paid"};
	public String con=null;
	
	JTable table;
	JTable tblInventory;
	JScrollPane scroll; 
	JScrollPane scrInventory;
	int r=0,q=0;
	static int RepID = 0;

	
	
	//buttons
	public JButton btnBack;
	public JButton btnLogOut;
	public JButton btnSubmitComp;
	public JButton btnOrders;
	public JButton btnBack1;
	public JButton btnSaveCompRep;
	public JButton btnSaveSatisRep;
	public JButton btnSaveInventoryRep;
	public JButton btnSubmitQuarter;

	//panels
	JPanel CostCompPanel;
	JPanel panelCompTbl;
	JPanel SatisPanel;
	JPanel pnlInventory;
	JPanel panelTable;
	JPanel quarterMenuRepPanel;
	JPanel quarterIncomePanelTable;
	JPanel orderRepPanel;
	
	//combo box
	JComboBox startDate;
	JComboBox endDate;
	JComboBox compOption;
	JComboBox quarterOptions;
	JComboBox month;
	
	//labels
	JLabel lblHeaderComp;
	JLabel lblHeaderOrder;
	JLabel lblHeaderSatisfaction;
	JLabel lblStartMonth;
	JLabel lblEndMonth;
	JLabel lblHeaderHandledComp;
	JLabel lblHeaderQuarterInc;
	JLabel lblCostOption;
	JLabel lblNumOfComp;
	JLabel lblHeaderInventory;
	JLabel lblQuarterMenu;
	JLabel lblQuarterOption;
	JLabel lblOrderTable;
	
	Container contentpane;
	
	public Report_GUI(int rep){
		
		super();
		q=rep;
		contentpane = this.getContentPane();
	    contentpane.setLayout(new BorderLayout(0, 0));
		this.setBounds((int)Main.dim.getWidth()/2-260, (int)Main.dim.getHeight()/2-275, 515, 550);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setTitle("Zer Lah - Reports");
		if(rep==1)
		{
			contentpane.add(getCostumerCompRepPanel(),BorderLayout.CENTER);
			this.setSize(500,400);
		}
		if(rep==2)
		{
			this.setSize(1000,400);
			contentpane.add(getSatisfactionRepPanel(),BorderLayout.CENTER);
			this.setBounds(150, 260, 1000, 400);
		}
		if(rep==3)
		{
			contentpane.add(getInventoryRepPanel(),BorderLayout.CENTER);
			this.setBounds(150, 260, 1000, 400);
			this.setSize(500,400);
		}
		if(rep==4)
		{
			contentpane.add(getQuarterMenuRepPanel(),BorderLayout.CENTER);
			this.setSize(500,400);
		}
		if(rep==5)
		{
			contentpane.add(getOrderRepPanel(),BorderLayout.CENTER);
			this.setSize(1000,400);
		}
		this.setVisible(true);	
	}
	
	JPanel getOrderRepPanel()
	{
		if(orderRepPanel==null)
		{
			orderRepPanel=new JPanel();
			orderRepPanel.setSize(500, 400);
			orderRepPanel.setLayout(null);
			orderRepPanel.add(getBtnBack());
			orderRepPanel.add(getBtnLogOut());
			orderRepPanel.add(getComboMonthOrder());
			orderRepPanel.add(getLabelHeaderOrder());
			orderRepPanel.add(getBtnSaveInventoryRep());
			orderRepPanel.add(getLabelStartMonth());
			orderRepPanel.add(getBtnSubComp());
			}
		return orderRepPanel;
	}
	
	JPanel getIncomePanelTable()
	{
		if(quarterIncomePanelTable==null)
		{
			quarterIncomePanelTable=new JPanel();
			quarterIncomePanelTable.setSize(1000, 400);
			quarterIncomePanelTable.setLayout(null);
			quarterIncomePanelTable.add(getBtnBack1());
			quarterIncomePanelTable.add(getBtnLogOut());
			quarterIncomePanelTable.add(getIncomeTable());
			quarterIncomePanelTable.add(getLabelHeaderQuarterInc());
			quarterIncomePanelTable.add(getBtnSaveInventoryRep());
		}
		return quarterIncomePanelTable;
	}
	
	JPanel getQuarterMenuRepPanel()
	{
		if(quarterMenuRepPanel==null)
		{
			quarterMenuRepPanel=new JPanel();
			quarterMenuRepPanel.setSize(500, 400);
			quarterMenuRepPanel.setLayout(null);
			quarterMenuRepPanel.add(getBtnBack());
			quarterMenuRepPanel.add(getBtnLogOut());
			//pnlInventory.add(getInventoryTable());
			quarterMenuRepPanel.add(getLabelHeaderMenu());
			quarterMenuRepPanel.add(getLabelQuarterOption());
			quarterMenuRepPanel.add(getComboQuarterOption());
			quarterMenuRepPanel.add(getBtnSubmitQuarter());
		
		}
		return quarterMenuRepPanel;
	}
	
	JPanel getInventoryRepPanel()
	{
		if(pnlInventory==null)
		{
			pnlInventory=new JPanel();
			pnlInventory.setSize(1000, 400);
			pnlInventory.setLayout(null);
			pnlInventory.add(getBtnBack());
			pnlInventory.add(getBtnLogOut());
			pnlInventory.add(getInventoryTable());
			pnlInventory.add(getLabelHeaderInventory());
			pnlInventory.add(getBtnSaveInventoryRep());
		}
		return pnlInventory;
	}
	
	JPanel getCostumerCompRepPanel() {	
		
		if (CostCompPanel == null){
			CostCompPanel = new JPanel();
			CostCompPanel.setSize(500, 400);
			CostCompPanel.setLayout(null);
			CostCompPanel.add(getBtnBack());
			CostCompPanel.add(getBtnLogOut());
			CostCompPanel.add(getComboStart());
			CostCompPanel.add(getComboEnd());
			CostCompPanel.add(getLabelHeaderComp());
			CostCompPanel.add(getLabelStartMonth());
			CostCompPanel.add(getLabelEndMonth());
			CostCompPanel.add(getBtnSubComp());
			CostCompPanel.add(getLabelCostOptions());
			CostCompPanel.add(getComboCompOption());
		}
		return CostCompPanel;
	}
	
	JPanel getSatisfactionRepPanel(){
		
		if(SatisPanel==null){
			SatisPanel = new JPanel();
			SatisPanel.setSize(1000, 400);
			SatisPanel.setLayout(null);
			SatisPanel.add(getBtnBack());
			SatisPanel.add(getBtnLogOut());
			SatisPanel.add(getSatisRepTable());
			SatisPanel.add(getLabelHeaderSatis());
			SatisPanel.add(getBtnSaveSatisRep());
		}
		return SatisPanel;
	}
	
	JPanel getCompPanelTable() {	
			
			if (panelCompTbl == null){
				panelCompTbl = new JPanel();
				panelCompTbl.setSize(1000, 400);
				panelCompTbl.setLayout(null);
				panelCompTbl.add(getBtnLogOut());
				panelCompTbl.add(getBtnBack1());
				panelCompTbl.add(getBtnSaveCompRep());
				if(q==1)
				{
					panelCompTbl.add(getCopRepTable());
					panelCompTbl.add(getLabelHeaderCompHangled());
					panelCompTbl.add(getLblNumOfComp());
				}
				if(q==5)
				{
					panelCompTbl.add(getOrderTable());
					panelCompTbl.add(getLabelHeaderOrderTable());
				}
			}
			return panelCompTbl;
		}
	
	JButton getBtnBack(){
			
		if (btnBack == null){
			btnBack = new JButton();
			if(q==1 || q==4 || q==5)
				btnBack.setBounds(380, 20, 100, 40);
			if(q==2 || q==3)
				btnBack.setBounds(880, 20, 100, 40);
			btnBack.setText("Back");
		}
		return btnBack;
	}
	
	JButton getBtnBack1(){
		
		if(btnBack1==null){
			btnBack1 = new JButton();
			btnBack1.setBounds(880, 20, 100, 40);
			btnBack1.setText("Back");
			btnBack1.addActionListener(this);
		}
		return btnBack1;
	}
	
	JButton getBtnSubmitOrder()
	{
		if(btnOrders==null)
		{
			btnOrders = new JButton();
			btnOrders.setBounds(150, 300, 200, 40);
			btnOrders.setText("Submit");
			btnOrders.addActionListener(this);
		}
		return btnOrders;
	}
	
	JButton getBtnSubComp(){
		
		if (btnSubmitComp == null){
			btnSubmitComp = new JButton();
			if(q==1)
				btnSubmitComp.setBounds(150, 320, 200, 40);
			else
				btnSubmitComp.setBounds(150, 300, 200, 40);
			btnSubmitComp.setText("Submit");
			btnSubmitComp.addActionListener(this);
		}
		return btnSubmitComp;
	}
		
	JButton getBtnLogOut() {
		
		if (btnLogOut == null){
			btnLogOut = new JButton();
			btnLogOut.setBounds(20,20,100,40);
			btnLogOut.addActionListener(this);
			btnLogOut.setText("LogOut");
		}
		return btnLogOut;
	}
	
	JButton getBtnSaveCompRep() {
			
		if (btnSaveCompRep == null){
			btnSaveCompRep = new JButton();
			btnSaveCompRep.setBounds(680, 300, 210, 40);
			btnSaveCompRep.addActionListener(this);
			btnSaveCompRep.setText("Save Report");
		}
			return btnSaveCompRep;
	}
	
	JButton getBtnSaveSatisRep() {
		
		if (btnSaveSatisRep== null){
			btnSaveSatisRep = new JButton();
			btnSaveSatisRep.setBounds(680, 300, 210, 40);
			btnSaveSatisRep.addActionListener(this);
			btnSaveSatisRep.setText("Save Report");
		}
		return btnSaveSatisRep;
	}
	
	JButton getBtnSaveInventoryRep() {
		
		if (btnSaveInventoryRep== null){
			btnSaveInventoryRep = new JButton();
			btnSaveInventoryRep.setBounds(680, 300, 210, 40);
			btnSaveInventoryRep.addActionListener(this);
			btnSaveInventoryRep.setText("Save Report");
		}
		return btnSaveInventoryRep;
	}
	
	JButton getBtnSubmitQuarter() {
		
		if (btnSubmitQuarter== null){
			btnSubmitQuarter = new JButton();
			btnSubmitQuarter.setBounds(150, 300, 200, 40);
			btnSubmitQuarter.addActionListener(this);
			btnSubmitQuarter.setText("Submit");
		}
		return btnSubmitQuarter;
	}
	
	JComboBox getComboStart()
	{
		if(startDate==null)
		{
			startDate=new JComboBox();
			for(int i=0;i<13;i++)
				startDate.addItem(months[i]);
				startDate.setBounds(280, 150, 150, 40);
		}
		return startDate;
	}
	

	JComboBox getComboEnd()
	{
		if(endDate==null)
		{
			endDate=new JComboBox();
			for(int i=0;i<13;i++)
				endDate.addItem(months[i]);
				endDate.setBounds(280, 210, 150, 40);
		}
		return endDate;
	}
	
	JComboBox getComboMonthOrder()
	{
		if(month==null)
		{
			month=new JComboBox();
			for(int i=0;i<13;i++)
				month.addItem(months[i]);
			month.setBounds(300, 150, 150, 40);
		}
		return month;
	}
	
	JComboBox getComboCompOption()
	{
		if(compOption==null)
		{
			compOption=new JComboBox();
			for(int i=0;i<2;i++)
				compOption.addItem(compOptions[i]);
			compOption.setBounds(280, 260, 150, 40);
		}
		return compOption;
	}
	
	JComboBox getComboQuarterOption()
	{
		if(quarterOptions==null)
		{
			quarterOptions=new JComboBox();
			for(int i=0;i<4;i++)
				quarterOptions.addItem(quarters[i]);
			quarterOptions.setBounds(280, 200, 150, 40);
		}
		return quarterOptions;
	}
	
	JLabel getLabelHeaderComp()
	{
		if(lblHeaderComp==null)
		{
			lblHeaderComp=new JLabel();
			lblHeaderComp.setText("Costumer Complaint Status Report");
			lblHeaderComp.setBounds(50, 100, 400, 40);
			lblHeaderComp.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeaderComp;
	}
	
	JLabel getLabelHeaderOrderTable()
	{
		if(lblOrderTable==null)
		{
			lblOrderTable=new JLabel();
			lblOrderTable.setText("Order Report");
			lblOrderTable.setBounds(400, 60, 200, 40);
			lblOrderTable.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblOrderTable;
	}
	
	JLabel getLabelHeaderQuarterInc()
	{
		if(lblHeaderQuarterInc==null)
		{
			lblHeaderQuarterInc=new JLabel();
			lblHeaderQuarterInc.setText("Quarter Income Report");
			lblHeaderQuarterInc.setBounds(350, 60, 400, 40);
			lblHeaderQuarterInc.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeaderQuarterInc;
	}
	
	JLabel getLabelHeaderOrder()
	{
		if(lblHeaderOrder==null)
		{
			lblHeaderOrder=new JLabel();
			lblHeaderOrder.setText("Order Report");
			lblHeaderOrder.setBounds(175, 60, 150, 40);
			lblHeaderOrder.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeaderOrder;
	}
	
	JLabel getLabelHeaderMenu()
	{
		if(lblQuarterMenu==null)
		{
			lblQuarterMenu=new JLabel();
			lblQuarterMenu.setText("Quarter Income Report Menu");
			lblQuarterMenu.setBounds(85, 100, 330, 40);
			lblQuarterMenu.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblQuarterMenu;
	}
	
	JLabel getLabelQuarterOption()
	{
		if(lblQuarterOption==null)
		{
			lblQuarterOption=new JLabel();
			lblQuarterOption.setText("Choose a quarter: ");
			lblQuarterOption.setBounds(30, 200, 180, 40);
			lblQuarterOption.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,18));
		}
		return lblQuarterOption;
	}
	
	JLabel getLabelHeaderSatis()
	{
		if(lblHeaderSatisfaction==null)
		{
			lblHeaderSatisfaction=new JLabel();
			lblHeaderSatisfaction.setText("Satisfaction Report");
			lblHeaderSatisfaction.setBounds(350, 60, 400, 40);
			lblHeaderSatisfaction.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeaderSatisfaction;
	}
	
	JLabel getLabelHeaderInventory()
	{
		if(lblHeaderInventory==null)
		{
			lblHeaderInventory=new JLabel();
			lblHeaderInventory.setText("Inventory Report");
			lblHeaderInventory.setBounds(350, 60, 400, 40);
			lblHeaderInventory.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeaderInventory;
	}
	
	JLabel getLabelHeaderCompHangled()
	{
		if(lblHeaderHandledComp==null)
		{
			lblHeaderHandledComp=new JLabel();
			lblHeaderHandledComp.setText("Costumer Complaint Status Report");
			lblHeaderHandledComp.setBounds(300, 60, 400, 40);
			lblHeaderHandledComp.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeaderHandledComp;
	}
	
	JLabel getLabelStartMonth()
	{
		if(lblStartMonth==null)
		{
			lblStartMonth=new JLabel();
			if(q==5)
				lblStartMonth.setText("Choose month");
			else
				lblStartMonth.setText("Choose beginning month");
			lblStartMonth.setBounds(20, 150, 210, 40);
			lblStartMonth.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,18));
		}
		return lblStartMonth;
	}
	
	JLabel getLabelEndMonth()
	{
		if(lblEndMonth==null)
		{
			lblEndMonth=new JLabel();
			lblEndMonth.setText("Until month");
			lblEndMonth.setBounds(20, 210, 210, 40);
			lblEndMonth.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,18));
		}
		return lblEndMonth;
	}
	
	JLabel getLabelCostOptions()
	{
		if(lblCostOption==null)
		{
			lblCostOption=new JLabel();
			lblCostOption.setText("Choose Type");
			lblCostOption.setBounds(20, 260, 210, 40);
			lblCostOption.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,18));
		}
		return lblCostOption;
	}
	
	JLabel getLblNumOfComp()
	{
		if(lblNumOfComp==null)
		{
			lblNumOfComp=new JLabel();
			lblNumOfComp.setText("Number Of Complaints : " +r );
			lblNumOfComp.setBounds(90, 300, 210, 40);
			lblNumOfComp.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,18));
		}
		return lblNumOfComp;
	}

	
	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource() == btnLogOut)
		{
			if(JOptionPane.showConfirmDialog(null,"Are you sure you want to logout?",null,JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
			{
				this.setEnabled(false);
				this.setVisible(false);
				Main.main.logOut.doClick();
			}
		}
		
		if(e.getSource() == btnSubmitComp)
		{
			if(q==1)
			{
				if(startDate.getSelectedItem().equals(" "))
					JOptionPane.showMessageDialog(null, "You must choose a month to start from!");
				else
				{
					String Smonth = (String)startDate.getSelectedItem();
					String Emonth = (String)endDate.getSelectedItem();
					con = (String)compOption.getSelectedItem();
					data = ReportControl.getCompStatReport(Smonth, Emonth, con);
					if(data.length==0)
						JOptionPane.showMessageDialog(null, "There are no complaints!");
					else
					{
						CostCompPanel=null;
						startDate=null;
						endDate=null;
						compOption=null;
						this.getContentPane().removeAll();
						this.getContentPane().add(getCompPanelTable(),BorderLayout.CENTER);
						this.setSize(1000, 400);
						this.setBounds(150, 260, 1000, 400);
						validate();
						setVisible(true);
					}
				}
			}
			if(q==5)
			{
				if(month.getSelectedItem().equals(" "))
					JOptionPane.showMessageDialog(null, "You must select a month!");
				else
				{
					con = (String)month.getSelectedItem();
					data = ReportControl.getOrderRep(con);
					if(data.length==0)
						JOptionPane.showMessageDialog(null, "There are no orders!");
					else
					{
						orderRepPanel=null;
						panelCompTbl=null;
						month=null;
						this.getContentPane().removeAll();
						this.getContentPane().add(getCompPanelTable(),BorderLayout.CENTER);
						this.setSize(1000, 400);
						this.setBounds(150, 260, 1000, 400);
						validate();
						setVisible(true);
					}
				}
			}
		}
		
		if(e.getSource() == btnSubmitQuarter)
		{
				String choice = (String)quarterOptions.getSelectedItem();
				data = ReportControl.getIncomeReport(choice);
				if(data.length==0)
					JOptionPane.showMessageDialog(null, "There is no income!");
				else
				{
					quarterMenuRepPanel=null;
					quarterOptions=null;
					this.getContentPane().removeAll();
					this.getContentPane().add(getIncomePanelTable(),BorderLayout.CENTER);
					this.setSize(1000, 400);
					this.setBounds(150, 260, 1000, 400);
					validate();
					setVisible(true);
				}
			
		}
		
		if(e.getSource() == btnBack1)
		{
			quarterIncomePanelTable=null;
			panelTable=null;
			panelCompTbl=null;
			
			table=null;
			scroll=null;
			this.getContentPane().removeAll();
			this.setBounds((int)Main.dim.getWidth()/2-260, (int)Main.dim.getHeight()/2-275, 515, 550);
			this.setSize(500, 400);
			if(q==4)
				this.getContentPane().add(getQuarterMenuRepPanel(),BorderLayout.CENTER);
			if(q==5)
				this.getContentPane().add(getOrderRepPanel(),BorderLayout.CENTER);
			if(q==1)
				this.getContentPane().add(getCostumerCompRepPanel(),BorderLayout.CENTER);
			validate();
			setVisible(true);
		}
		
		if(e.getSource() == btnSaveCompRep)
		{
			
			if(q==1)
			{
				if(con.equals("handled"))
				{
				RepID=ReportControl.getRepID(1);
				for(int i=0,j=0 ; i<table.getRowCount() ; i++ )
					{
						String z = table.getValueAt(i, j).toString();
						String x = table.getValueAt(i, j+3).toString();
						ReportControl.saveCompRep(Integer.toString(RepID),z,x);
					}		
				JOptionPane.showMessageDialog(null, "Report Saved!");
				btnBack1.doClick();
				}
				else
					JOptionPane.showMessageDialog(null, "Cannot save unhandled complaints!");
			}
			if(q==5)
			{
				if(table.getRowCount()!=0)
				{
					String []avg = new String[8];
					RepID=ReportControl.getRepID(5);
					avg[0] = "save order report";
					avg[1] = Integer.toString(RepID);
					for(int i=0 ; i<table.getRowCount() ; i++ )
					{
						for(int j=2 ; j<8 ; j++)
						{
							avg[j] = table.getValueAt(i, j-2).toString();
						}
						ReportControl.saveOrderRep(avg);	
					}
					JOptionPane.showMessageDialog(null, "Report Saved!");	
				}
				else
					JOptionPane.showMessageDialog(null, "There are no orders to save!");
				btnBack1.doClick();
			}
		}
		
		if(e.getSource() == btnSaveSatisRep)
		{
			if(table.getRowCount()!=0)
			{
				String []avg = new String[9];
				RepID = ReportControl.getRepID(2);
				avg[0] = "save satisfaction report";
				avg[8] = Integer.toString(RepID);
				for(int i=0 ; i<table.getRowCount() ; i++ )
				{
					for(int j=1 ; j<8 ; j++)
						avg[j] = table.getValueAt(i, j-1).toString();
					ReportControl.saveSatisRep(avg);	
				}
							
				JOptionPane.showMessageDialog(null, "Report Saved!");	
			}
			else
				JOptionPane.showMessageDialog(null, "There are no new details to save!");
			btnBack.doClick();
		}
		
		if(e.getSource() == btnSaveInventoryRep)
		{
			if(q==3)
			{
			String []avg = new String[5];
			RepID = ReportControl.getRepID(3);
			avg[0] = "save inventory report";
			avg[1] = Integer.toString(RepID);
			for(int i=0 ; i<tblInventory.getRowCount() ; i++ )
			{
				for(int j=2 ; j<5 ; j++)
					avg[j] = tblInventory.getValueAt(i, j-2).toString();
				ReportControl.saveInventoryRep(avg);	
			}
						
			JOptionPane.showMessageDialog(null, "Report Saved!");	
			btnBack.doClick();
			}
			if(q==4)
			{
				String []avg = new String[6];
				RepID = ReportControl.getRepID(4);
				avg[0] = "save income report";
				avg[1] = Integer.toString(RepID);
				for(int i=0 ; i<table.getRowCount() ; i++ )
				{
					for(int j=2 ; j<6 ; j++)
						avg[j] = table.getValueAt(i, j-1).toString();
					ReportControl.saveIncomeRep(avg);	
				}
				JOptionPane.showMessageDialog(null, "Report Saved!");	
				btnBack.doClick();
			}
		}
		
	}
	
	JScrollPane getCopRepTable(){
		
		  DefaultTableModel model = new DefaultTableModel(data, columnNames) {
		      public boolean isCellEditable(int rowIndex, int mColIndex) {
		      return false;
		      }
		  };
		  table = new JTable(model); 
		  table.getModel().addTableModelListener(this);
		  r = table.getRowCount();
		  lblNumOfComp=null;
		  TableColumn column = table.getColumnModel().getColumn(2);
		  column.setPreferredWidth(100);
		  column = table.getColumnModel().getColumn(0);
		  column.setPreferredWidth(0);
		  column = table.getColumnModel().getColumn(1);
		  column.setPreferredWidth(100);
	      scroll = new JScrollPane(table); 
	      scroll.setBounds(90, 120, 800, 140);
	      table.setBounds(90, 120, 800, 140);
	      return scroll; 
	}
	
	JScrollPane getSatisRepTable(){
		
		  data = ReportControl.getSatisfactionReport();
		  DefaultTableModel model = new DefaultTableModel(data, columnNames1) {
		      public boolean isCellEditable(int rowIndex, int mColIndex) {
		      return false;
		      }
		  };
		  table = new JTable(model);
		  table.getModel().addTableModelListener(this);
		  r = table.getRowCount();
		  lblNumOfComp=null;
	      scroll = new JScrollPane(table); 
	      scroll.setBounds(90, 120, 800, 140);
	      table.setBounds(90, 120, 800, 140);
	      return scroll; 
		 // }
	}
	
	JScrollPane getInventoryTable()
	{
		data=ReportControl.getInventoryReport();
		DefaultTableModel model = new DefaultTableModel(data, columnInventory) {
		      public boolean isCellEditable(int rowIndex, int mColIndex) {
		      return false;
		      }
		  };
		  tblInventory=new JTable(model);
		  tblInventory.getModel().addTableModelListener(this);
		  scrInventory=new JScrollPane(tblInventory);
		  scrInventory.setBounds(90, 120, 800, 140);
		  return scrInventory;
	}
	
	JScrollPane getIncomeTable()
	{
		DefaultTableModel model = new DefaultTableModel(data, columnIncome) {
		      public boolean isCellEditable(int rowIndex, int mColIndex) {
		      return false;
		      }
		  };
		  table=new JTable(model);
		  table.getModel().addTableModelListener(this);
		  scroll=new JScrollPane(table);
		  scroll.setBounds(90, 120, 800, 140);
		  return scroll;
	}
	
	JScrollPane getOrderTable()
	{
		
		DefaultTableModel model = new DefaultTableModel(data, columnOrder) {
		      public boolean isCellEditable(int rowIndex, int mColIndex) {
		      return false;
		      }
		  };
		  table = new JTable(model);
		  TableColumn column = table.getColumnModel().getColumn(5);
		  column.setCellEditor(new DefaultCellEditor(new JCheckBox()));
		  table.getColumnModel().getColumn(5).setCellRenderer(
					new TableCellRenderer() {
						 public Component getTableCellRendererComponent(
									JTable table, Object value, boolean isSelected,
									boolean isFocused, int row, int col) {
								boolean marked = (Boolean) value;
								JCheckBox rendererComponent = new JCheckBox();
								if (marked) {
									rendererComponent.setSelected(true);
								}
								return rendererComponent;
							}
						});
		  table.getModel().addTableModelListener(this);
		  scroll=new JScrollPane(table);
		  scroll.setBounds(90, 120, 800, 140);
		return scroll;
	}
	
	
	public void tableChanged(TableModelEvent arg0) {
	}

}
